<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*
       * 箭头函数
       * 1.没有this,arguments,箭头函数中this==window
       * 2.不能作为构造函数
       */

      var person = {
        name: '张三',
        run: function (time) {
          console.log(`${this.name}在跑步 最多${time}分钟`)
        }
      }
      person.run(30)
      person.run.call(person, 30)

      var x = 11
      var obj = {
        x: 22,
        say: () => {
          // this指向window
          console.log(this.x)
        }
      }
      obj.say()

      var obj = {
        birth: 1990,
        getAge: function () {
          var b = this.birth
          // this指向obj
          var fn = () => new Date().getFullYear() - this.birth
          return fn()
        }
      }
      console.log(obj.getAge())
    </script>
  </body>
</html>
